package com.yiwei.zxp.view;

import android.app.Dialog;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.yiwei.zxp.R;
import com.yiwei.zxp.activity.QuickListActivity;
import com.yiwei.zxp.util.ToastUtil;
import com.yiwei.zxp.util.UI;
import com.yiwei.zxp.util.Util;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by xsooy-pc on 18-5-22.
 */

public class QuickInfoDilaog extends Dialog {

    @BindView(R.id.btn_cancel)
    ImageView btnCancel;
    @BindView(R.id.txt_quick_name)
    TextView txtQuickName;
    @BindView(R.id.edit_quick_num)
    EditText editQuickNum;
    @BindView(R.id.btn_submit)
    TextView btnSubmit;

    private Context context;
    private String express_id;
    private String order_no;

    public QuickInfoDilaog(Context context) {
        this(context, R.style.DialogStyle);
    }

    public QuickInfoDilaog(Context context, int themeResId) {
        super(context, themeResId);
        this.context = context;
        initView();
    }

    private void initView() {
        setContentView(R.layout.dialog_quick_info);
        ButterKnife.bind(this);
        setCancelable(false);

        Window mWindow = getWindow();
        WindowManager.LayoutParams lp = mWindow.getAttributes();
        lp.width = Util.getDisplayMetrics(context).widthPixels;
        lp.gravity = Gravity.BOTTOM;
        mWindow.setAttributes(lp);


    }

    @Override
    public void show() {
        super.show();
        txtQuickName.setText("");
        editQuickNum.setText("");
    }

    public void setOrder_no(String order_no) {
        this.order_no = order_no;
    }

    public void setTxtQuickName(String id, String quickname) {
        express_id = id;
        txtQuickName.setText(quickname);
    }

    private OnChooseListener onChooseListener;

    public QuickInfoDilaog setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
        return this;
    }

    @OnClick({R.id.btn_cancel, R.id.txt_quick_name, R.id.btn_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_cancel:
                dismiss();
                break;
            case R.id.txt_quick_name:
                Util.startActivity(context, QuickListActivity.class);
                break;
            case R.id.btn_submit:
                if (TextUtils.isEmpty(UI.toString(txtQuickName))) {
                    ToastUtil.makeText(context, "快递公司不能为空");
                    return;
                } else if (TextUtils.isEmpty(UI.toString(editQuickNum))) {
                    ToastUtil.makeText(context, "快递单号不能为空");
                    return;
                }
                com.yiwei.zxp.util.Dialog.showDefaultDialog(context, "", "是否已认真确认快递信息了？", "我再看看", "确定", false, new com.yiwei.zxp.util.Dialog.DialogDefaultClickListener() {
                    @Override
                    public void confirm() {
                        if (onChooseListener != null) {
                            onChooseListener.onSuccess(order_no, express_id, UI.toString(editQuickNum));
                        }
                        dismiss();
                    }

                    @Override
                    public void cancel() {

                    }
                });


                break;
        }
    }


    public interface OnChooseListener {
        void onSuccess(String order_no, String express_id, String express_no);
    }
}
